package com.longevityassistant.activity.home;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import app.utils.CommonUtils;

import com.longevityassistant.activity.BaseActivity;
import com.longevityassistant.activity.R;
import com.longevityassistant.adapter.MemberAdapter;
import com.longevityassistant.struct.Member;

public class FamilyListActivity  extends BaseActivity implements OnItemClickListener{
	
	private ListView mListView;
	
	private ArrayList<Member> listData;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_family_list);
		
		setTopImgTitle(R.drawable.logo);
		
		mListView = (ListView) findViewById(R.id.listview_family_list);
		
		listData = getMemberList();
		
		MemberAdapter ma = new MemberAdapter(this,listData);
		
		mListView.setAdapter(ma);
		mListView.setOnItemClickListener(this);
	}
	
	private ArrayList<Member> getMemberList(){
		ArrayList<Member>  list = new ArrayList<Member> ();
		Member m = new Member();
		
		m.name = "小明";
		m.resIcon = R.drawable.sys_head_portrait_01;
		m.healthLevel1 = 10;
		m.healthLevel2 = 10;
		m.healthLevel3 = 10;
		m.healthLevel4 = 10;
		m.healthLevel5 = 10;
		m.valuse = 70;
		list.add(m);
		
		m = new Member();
		m.name = "张XX";
		m.resIcon = R.drawable.sys_head_portrait_03;
		m.healthLevel1 = 20;
		m.healthLevel2 = 30;
		m.healthLevel3 = 40;
		m.healthLevel4 = 20;
		m.healthLevel5 = 10;
		m.valuse = 90;
		list.add(m);
		
		m = new Member();
		m.name = "李XX";
		m.resIcon = R.drawable.sys_head_portrait_06;
		m.healthLevel1 = 20;
		m.healthLevel2 = 30;
		m.healthLevel3 = 40;
		m.healthLevel4 = 20;
		m.healthLevel5 = 10;
		m.valuse = 55;
		list.add(m);
		
		return list;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Member m = listData.get(position);
		HomeServerActivity.mMember = m;
		Intent intent = new Intent(this, HomeServerActivity.class);
		this.startActivity(intent);
		
	}
	
	@Override  
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{ 
		if(keyCode == KeyEvent.KEYCODE_BACK)
		{ 
			// 退出提示 对话框
			CommonUtils.showTipDialog(this, getString(R.string.msg_exit));
				
			return true;
		}
		
        return super.onKeyDown(keyCode, event);
	} 
}